package com.ruoyi.system.controller;


import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.idempotent.annotation.RepeatSubmit;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.food.api.model.FoodDiscountVo;
import com.ruoyi.system.domain.ActivityDiscount;
import com.ruoyi.system.service.ActivityDiscountService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 活动折扣控制器
 *
 * @author Administrator
 * @date 2023/03/13
 */
@RestController
@RequestMapping("/activity/discount")
@RequiredArgsConstructor
public class ActivityDiscountController extends BaseController {

    private final ActivityDiscountService activityDiscountService;

    /**
     * 页面活动折扣
     *
     * @param activityDiscount 活动折扣
     * @param pageQuery        页面查询
     * @return {@link TableDataInfo}<{@link ActivityDiscount}>
     */
    @GetMapping("/page")
    public TableDataInfo<ActivityDiscount> pageActivityDiscount(ActivityDiscount activityDiscount, PageQuery pageQuery) {
        return activityDiscountService.pageActivityDiscount(activityDiscount, pageQuery);
    }


    /**
     * 保存
     *
     * @param activityDiscount 活动折扣
     * @return {@link R}<{@link Void}>
     */
    @RepeatSubmit
    @PostMapping
    public R<Void> save(@RequestBody ActivityDiscount activityDiscount) {
        return toAjax(activityDiscountService.saveActivityDiscount(activityDiscount));
    }

    /**
     * 修改
     *
     * @param activityDiscount 活动折扣
     * @return {@link R}<{@link Void}>
     */
    @PutMapping
    @RepeatSubmit
    public R<Void> update(@RequestBody ActivityDiscount activityDiscount) {
        return toAjax(activityDiscountService.updateActivityDiscount(activityDiscount));
    }

    /**
     * 信息
     *
     * @param discountId 折扣id
     * @return {@link R}<{@link ActivityDiscount}>
     */
    @GetMapping("/{discountId}")
    public R<ActivityDiscount> info(@PathVariable("discountId") Long discountId) {
        return R.ok(activityDiscountService.getActivityDiscountById(discountId));
    }

    /**
     * 分页菜品详情
     *
     * @param activityDiscount 活动折扣
     * @param pageQuery        页面查询
     * @return {@link TableDataInfo}<{@link FoodDiscountVo}>
     */
    @GetMapping("/page/food_detail")
    public TableDataInfo<FoodDiscountVo> pageFoodDetail(ActivityDiscount activityDiscount, PageQuery pageQuery) {
        return activityDiscountService.pageFoodDetail(activityDiscount, pageQuery);
    }

    /**
     * 删除
     *
     * @param discountIds 折扣id
     */
    @DeleteMapping
    public R<Void> delete(@RequestBody List<Long> discountIds) {
        activityDiscountService.deleteByIds(discountIds);
        return R.ok();
    }

}
